package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.IPatrolOrderDetailView;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolOrderBean;
import com.cloudsigns.factorymanager2.engineering.model.IPatrolOrderDetailModel;

import com.cloudsigns.factorymanager2.engineering.model.PatrolOrderDetailModel;

/**
 * Created by tony on 2018/5/8.
 */

public class PatrolOrderDetailPresenter {
    private IPatrolOrderDetailView view;
    private IPatrolOrderDetailModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public PatrolOrderDetailPresenter(IPatrolOrderDetailView view) {
        this.view = view;
        this.model = new PatrolOrderDetailModel();
    }

    public void getPatrolOrderDetail() {


        model.getPatrolOrderDetail(view.getOrderId(), view.getItemId(),
                new PatrolOrderDetailModel.OnPatrolOrderDetailModelListener() {
                    @Override
                    public void getPatrolOrderDetailSuccessed(final PatrolOrderBean patrolOrderBean) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.getPatrolOrderDetailSuccessed(patrolOrderBean);
                                view.hideLoading();
                            }
                        });
                    }

                    @Override
                    public void getPatrolOrderDetailFailed(final String desc) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                view.gPatrolOrderDetailFailed(desc);
                                view.hideLoading();
                            }
                        });
                    }
                });

    }
}
